// Class to read and write to Excel by wps
//
// Created by tredy
// December 2008
// 
// Version 1.2

#if !defined(_CONTROLWPS_H_)
#define _CONTROLWPS_H_

#include <atlbase.h>
#include "..\GlobalFile\ZGlobalHead.h"

class CControlWPS  
{
public:
	CControlWPS();
	~CControlWPS();
public:
	BOOL OpenWPS(const CString& sFilePath);
	BOOL OpenSheet(const CString& sSheet);
	BOOL ReadCell (CString &CellValue, long column, long row);
	BOOL WriteCell (const CString& sCellValue, long column, long row);
	BOOL Commit(); // Save changes to spreadsheet
	void CloseWPS();
	const vecStr& GetSheetNames() const { return m_vecSheetNames;	};
private:
	IDispatch* m_pIDisp;
	VARIANT varWorkbook;
	VARIANT varSheets;
	VARIANT varActiveSheet;
	vecStr m_vecSheetNames;
private:
	HRESULT GetProperty(IDispatch *pDisp, LPCOLESTR lpsz, VARIANT *pVar);
	HRESULT PutProperty(IDispatch *pDisp, LPCOLESTR lpsz, VARIANT *pVar);
	HRESULT GetPropertyN(IDispatch *pDisp, LPCOLESTR lpsz, VARIANT *varParams, int nParams, VARIANT *pVar);
	HRESULT PutPropertyN(IDispatch *pDisp, LPCOLESTR lpsz, VARIANT *varParams, int nParams, VARIANT *pVar);
	HRESULT Invoke0(IDispatch *pDisp, LPCOLESTR lpszName, VARIANT *pvarRet);
	HRESULT InvokeN(IDispatch *pDisp, LPCOLESTR lpszName, VARIANT *varParams, int nParams, VARIANT *pvarRet);
	CString VariantToCString(VARIANT var);
};

#endif // !defined(_CONTROLWPS_H_)
